package com.guaju.yueshangLife.widget.mine;

import android.content.Context;
import android.content.res.TypedArray;
import android.databinding.DataBindingUtil;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.databinding.TextBarDividerBinding;
import com.guaju.yueshangLife.databinding.TitleMoreLineBinding;

public class TitleMoreLine extends FrameLayout {
    LayoutInflater inflater;
    TitleMoreLineBinding binding;

    public TitleMoreLine(Context context) {
        super(context);
        inflater = LayoutInflater.from(context);
        init();
    }

    public TitleMoreLine(Context context, AttributeSet attrs) {
        super(context, attrs);
        inflater = LayoutInflater.from(context);
        init();
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.title_more_line);
        String barTitle = typedArray.getString(R.styleable.title_more_line_ltitle);
        String rtxt = typedArray.getString(R.styleable.title_more_line_rtxt);
        boolean showArraw = typedArray.getBoolean(R.styleable.title_more_line_showarrow, true);
        int color = typedArray.getColor(R.styleable.title_more_line_rcolor, getResources().getColor(R.color.grey_333));

        binding.title.setText(barTitle);
        if (TextUtils.isEmpty(rtxt)) {
            binding.tvRight.setVisibility(View.GONE);
        } else {
            binding.tvRight.setVisibility(View.VISIBLE);
            binding.tvRight.setText(rtxt);
        }
        if (showArraw) {
            binding.ivArrow.setVisibility(View.VISIBLE);
        } else {
            binding.ivArrow.setVisibility(View.GONE);
        }
        binding.tvRight.setTextColor(color);

    }

    private void init() {
        binding = (TitleMoreLineBinding) DataBindingUtil.inflate(inflater, R.layout.title_more_line, this, true);
    }

    public void setRightTv(String str){
        binding.tvRight.setText(str);
    }
    public void setRightArrawVisiable(boolean value){
        if (value){
            binding.ivArrow.setVisibility(View.VISIBLE);
        }else{
            binding.ivArrow.setVisibility(View.INVISIBLE);
        }
    }

}
